JwtSecurityTokenHandler.CreateToken で署名するときに「無効なアルゴリズムが指定されました」 ("Invalid algorithm specified" when signing with JwtSecurityTokenHandler.CreateToken)


問題の説明

JwtSecurityTokenHandler.CreateToken で署名するときに「無効なアルゴリズムが指定されました」 ("Invalid algorithm specified" when signing with JwtSecurityTokenHandler.CreateToken)

数年間、問題なく JWT トークンに署名しています。最近 Windows 10 にアップグレードしましたが、JWT トークンに署名しようとすると、「指定されたアルゴリズムが無効です」という CryptographicException が発生します。

このメソッドに X509Certificate2 を渡していますが、他に何もしていません。

System.IdentityModel.Tokens.JwtSecurityTokenHandler.CreateToken()

署名証明書は以前は SHA‑1 を使用して作成されていたので、SHA‑256 RSA を使用して新しい署名証明書を作成しましたが、それでも満足できませんでした.

いくつか読んだ「Microsoft Enhanced RSA and AES Cryptographic Provider」を有効にするか、少なくともそれを使用して署名証明書を作成する必要があることを示唆するSOの質問。多くの SO Qu がこの行を追加することを提案しましたが、まだ成功していません。

CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig‑more#rsa‑sha256");

また、このアルゴリズムがレジストリにあることも確認し、プロバイダー リストとプロバイダー タイプ リストで見つけました。残念ながら、Jwt 署名コードが System.Identity ライブラリ内にすべて隠されているため、どのアルゴリズムを使用するかを制御することはできません。前述の「強化された」ものではなく、「Microsoft Strong Cryptographic Provider」の RSA プロバイダーですが、MSDN のドキュメントからはほとんど同じように見えます。署名証明書を読み取ったり解釈したりするためのアルゴリズムではなく、実際のトークンに署名するために使用されるアルゴリズムを見つけますか?

JwtSecurityTokenHandler コードの限られた柔軟性で他にどのようなチェックを行うことができますか?<


リファレンスソリューション

方法 1:

I recently had to tackle the exact same issue.

TL;DR; You need to use "Microsoft Enhanced RSA and AES Cryptographic Provider", as opposed to what I suspect you are using which is "Microsoft Enhanced Cryptographic Provider v1.0".

You can find a full explanatory [ReadME][2], and source code at Karama.Jwt.Public. I happen to be using a different library for generating my JWT, namely JOSE, but I think that this is incidental.

Please let me know how you get on.

(by peter.swallowDarren Schwarz)

リファレンスドキュメント

  1. "Invalid algorithm specified" when signing with JwtSecurityTokenHandler.CreateToken (CC BY‑SA 2.5/3.0/4.0)

#signing #cryptography #sha256 #jwt #rsa






関連する質問

Google アクセス トークンを使用してユーザー プロファイルを取得するにはどうすればよいですか (How do I get user profile using Google Access Token)

コード署名ツールでMac開発者証明書を使用してJavaアプリケーションに署名するにはどうすればよいですか? (How to use Mac Developer Certificate with codesign tool to sign Java application?)

apk の署名中にエラーが発生しました: 見つかりません (Error during signing apk: unable to find)

JwtSecurityTokenHandler.CreateToken で署名するときに「無効なアルゴリズムが指定されました」 ("Invalid algorithm specified" when signing with JwtSecurityTokenHandler.CreateToken)

アセンブリの FullName プロパティのチェックを無効にできますか? 厳密な命名を使用せずに同様のチェックを実行できますか? (Can a check on the FullName property of an assembly be defeated? Can a similar check be performed without the use of strong naming?)

Cordova Build.json のパスワード セキュリティ (Cordova Build.json password security)

アプリリリース用の keytool による秘密鍵の取得 (Obtaining a private key through the keytool for app release)

android bundleRelease は aab に署名しません (android bundleRelease does not sign the aab)

証明書に iOS 署名証明書を作成する (create ios signing certificate in my certificates)

APKに署名する必要がある理由は何ですか? (What reasons does it have to sign apk?)

signtool.exe エラー: Excel マクロの署名時に SignerSign() が失敗しました (-2147220492/0x800403f4) (signtool.exe Error: SignerSign() failed (-2147220492/0x800403f4) when signing Excel Macro)

署名付き URL のこの実装は、かなり安全ですか? (Is this implementation of signed URLs reasonably secure?)







コメント